package cn.hxlc.tie.demo.modular.ljt.equipment.service.impl;

import cn.hutool.core.map.MapBuilder;
import cn.hxlc.tie.demo.modular.ljt.equipment.entity.MaterialGroup;
import cn.hxlc.tie.demo.modular.ljt.equipment.mapper.MaterialGroupMapper_lt;
import cn.hxlc.tie.demo.modular.ljt.equipment.service.MaterialService_lt;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static cn.hxlc.tie.demo.core.constant.TreeConst.ROOT_ID;
import static cn.hxlc.tie.demo.core.constant.TreeConst.ROOT_PID;


@Service
@Transactional
public class MaterialServiceImpl_lt extends ServiceImpl<MaterialGroupMapper_lt, MaterialGroup> implements MaterialService_lt {


    @Override
    public List<Map<String, Object>> queryTree() {
        List<Map<String,Object>> treeMaps =
                this.listMaps(new QueryWrapper<MaterialGroup>().select("fid as nodeId","fname as nodeName","fparentid as nodePid"));
        //装配根节点
        Map<String, Object> mapBuilder = MapBuilder.create(new HashMap<String, Object>())
                .put("nodeId",ROOT_ID)
                .put("nodeName","物料分类")
                .put("nodePid",ROOT_PID).build();
        treeMaps.add(mapBuilder);
        return treeMaps;
    }
}
